const list = [
  {
    name: 'aa',
    children: [
      {
        name: 'ee'
      }
    ]

  },
  {
    name: 'bb',
    children: [
      {
        name: 'ee',
        children: [
          {
            name: 'aa'
          },
          {
            name: 'cc'
          }
        ]
      },
    ]
  }
]
// 找出name=‘aa’的所有元素

function fn(list) {
  let result = []
  let isHash = false
  const find = (children) => {
    for (let i = 0; i < children.length; i++) {
      let item = children[i]
      if (item.name === 'aa') {
        isHash = true
        return
      } else {
        find(item.children || [])
      }
    }
    return isHash
  }
  list.forEach((item, index) => {
    if (item.name === 'aa') {
      result.push(item)
    } else {
      // 查找他的children
      const ishash = find(item.children || [])
      console.log(ishash)
      if (ishash) {
        result.push(item)
      }
    }
  })

  console.log(result)
  return result

}

fn(list)